package com.skyolder.crutch.word;

import com.skyolder.crutch.error.EofError;
import com.skyolder.crutch.error.GrammarError;
import com.skyolder.crutch.word.raw.TokenPiper;
import com.skyolder.crutch.word.token.Token;
import com.skyolder.crutch.word.token.raw.RawToken;
import com.skyolder.crutch.word.types.RawTokenType;

public class FilterTokenPiper {
	private TokenPiper tokenPiper=null;
	public FilterTokenPiper(TokenPiper tokenPiper){
		this.tokenPiper=tokenPiper;
	}
	public Token nextToken() throws GrammarError {
		while(true){
			RawToken rt=tokenPiper.nextRawToken();
			if(rt.getTokenType()==RawTokenType.NEWLINE){
				continue;
			}
			if(rt.getTokenType()==RawTokenType.NOTES){
				continue;
			}
			if(rt.getTokenType()==RawTokenType.SPACE){
				continue;
			}
			if(rt.getTokenType()==RawTokenType.EOF){
				throw EofError.instance;
			}
			if(rt.getTokenType()==RawTokenType.NULL){
				throw new GrammarError("null");
			}		
			return TokenBuilder.build(rt);
		}
	}
}
